import 'package:video_player/video_player.dart';

class VideoModel {
  VideoModel(
      {this.gameTitle,
      this.gameIcon,
      this.gameCoverImg,
      this.gameDesc,
      this.videoTitle,
      this.videoPlayURL,
      this.videoDuration,
      this.userName,
      this.userAvatar,
      this.playCount,
      this.upsCount,
      this.favoritesCount,
      this.commentsCount,
      this.date});

  VideoModel.fromJson(dynamic json)
      : gameTitle = json['gameTitle'],
        gameIcon = json['gameIcon'],
        gameCoverImg = json['gameCoverImg'],
        gameDesc = json['gameDesc'],
        videoTitle = json['videoTitle'],
        videoPlayURL = json['videoPlayURL'],
        videoDuration = json['videoDuration'],
        userName = json['userName'],
        userAvatar = json['userAvatar'],
        playCount = json['playCount'],
        upsCount = json['upsCount'],
        favoritesCount = json['favoritesCount'],
        date = json["date"],
        commentsCount = json['commentsCount'];

  VideoPlayerController? controller;

  String? gameTitle;
  String? gameIcon;
  String? gameCoverImg;
  String? gameDesc;
  String? videoTitle;
  String? videoPlayURL;
  int? videoDuration;
  String? userName;
  String? userAvatar;
  String? date;
  bool hasFav = false;
  int? playCount;
  int? upsCount;
  int? favoritesCount;
  int? commentsCount;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['gameTitle'] = gameTitle;
    map['gameIcon'] = gameIcon;
    map['gameCoverImg'] = gameCoverImg;
    map['gameDesc'] = gameDesc;
    map['videoTitle'] = videoTitle;
    map['videoPlayURL'] = videoPlayURL;
    map['videoDuration'] = videoDuration;
    map['userName'] = userName;
    map['userAvatar'] = userAvatar;
    map['playCount'] = playCount;
    map['upsCount'] = upsCount;
    map['favoritesCount'] = favoritesCount;
    map['commentsCount'] = commentsCount;
    map["date"] = date;
    return map;
  }

  Future<void> loadController() async {
    controller = VideoPlayerController.network(videoPlayURL ?? "");
    await controller?.initialize();
    await controller?.setLooping(true);
  }
}
